/*==============================================================================
**                                  FROGBOOT
**                      Proprietary - Copyright (C) 2014
**------------------------------------------------------------------------------
** Supported MCUs      : MCU STM32
** Supported Compilers : KeilC
**------------------------------------------------------------------------------
** File name         : ComM.h
**  
** Module name       : Communication Management
**
** Summary: Header file of communication Management module
**
**= History ===================================================================
** 00.00.01  15/1/2014  Cuong Chu
**          - Creation
** 00.00.01  29/7/2014  Cuong Chu
**          - Added definition of COM4, COM5 
**          - ComM_Init : added COM name input parameter
==============================================================================*/
#ifndef __COM_M_H__
#define __COM_M_H__
/******************************************************************************/
/* INCLUSIONS                                                                 */
/******************************************************************************/
#include "stdint.h"
#include "ComM/ComM_Cfg.h"
/******************************************************************************/
/* DEFINITION OF TYPES                                                        */
/******************************************************************************/
/* list com support */
typedef enum
{
  COMM_COM1 = 0,
  COMM_COM2,
  COMM_COM3,
  COMM_COM4,
  COMM_COM5,
  COMM_LIMIT
}ComM_PortType;
/* ComM message type */
typedef struct 
{
  ComM_PortType    Port;                      /* Com channel */
  uint32_t         SrcID;                     /* ID of transmitter */
  uint32_t         DstID;                     /* ID of node receive */
  uint8_t          Data[COMM_DATA_LENGTH];    /* User data */
  uint8_t          Dlc;                       /* data length code */
  uint8_t          MsgID;                     /* ID of message */
  uint8_t          rxChksum;                  /* received checksum data */
}ComM_MessageType;
/* ComM Return values*/
typedef enum
{
	COMM_OK,
  COMM_FAILED,
  COMM_PORT_INVALID,
  COMM_RX_AVAILABLE,
  COMM_RX_EMPTY,
  COMM_TX_AVAILABLE,
  COMM_OVERLOAD_TX,
}ComM_ReturnType;
/*******************************************************************************/
/* DECLARATION OF GLOBAL FUNCTIONS                                             */
/*******************************************************************************/
/*******************************************************************************
** Function name: ComM_Init( uint32_t NodeID,ComM_PortType ComX )
** Description  : The function shall be init module, include hardware and software
** Parameter    : NodeID - network node ID
**                ComX - COM port name
** Return value : ComM_ReturnType 
** Remarks      : global variables used, side effects
*******************************************************************************/
ComM_ReturnType ComM_Init 
(
  uint32_t               NodeID,
  ComM_PortType          ComX
);
/*******************************************************************************
** Function name: ComM_MainFunction( void )
** Description  : The function processes trasmit data and receive ACK/ACK
** Parameter    : None
** Return value : None 
** Remarks      : global variables used, side effects
*******************************************************************************/
void ComM_MainFunction 
(
  void
);
/*******************************************************************************
** Function name: ComM_AddMessageToQueue( ComM_MessageType* Msg )
** Description  : The function adds one COM message to Tx queue
** Parameter    : Msg - point to message send
** Return value : 
**                  COMM_OK      - if process success
**                  COMM_FAILED  - unknown error
**                  COMM_PORT_INVALID - port name is invalid
**                  COMM_OVERLOAD_TX  - TX queue is overload
** Remarks      : global variables used, side effects
*******************************************************************************/
ComM_ReturnType ComM_AddMessageToQueue
(
  ComM_MessageType* Msg
);
/*******************************************************************************
** Function name: ComM_ReadMsgFromQueue( ComM_MessageType* Msg )
** Description  : The function reads one message from Rx queue
** Parameter    : Msg - point to message read
** Return value :  
**                  COMM_OK      - if process success
**                  COMM_FAILED  - unknown error
**                  COMM_PORT_INVALID - port name is invalid
**                  COMM_OVERLOAD_TX  - TX queue is overload
** Remarks      : global variables used, side effects
*******************************************************************************/
ComM_ReturnType ComM_ReadMsgFromQueue
(
  ComM_MessageType* Msg
);
/*******************************************************************************
** Function name: ComM_EnableReceivePort( ComM_PortType ComName )
** Description  : The function enables receive data on port selected
** Parameter    : ComName - Name of port
** Return value : None 
** Remarks      : global variables used, side effects
*******************************************************************************/
void ComM_EnableReceivePort
(
  ComM_PortType ComName
);
/*******************************************************************************
** Function name: ComM_DisableReceivePort( ComM_PortType ComName )
** Description  : The function disables receive data on port selected
** Parameter    : ComName - Name of port
** Return value : None 
** Remarks      : global variables used, side effects
*******************************************************************************/
void ComM_DisableReceivePort
(
  ComM_PortType ComName
);
#endif /* __COM_M_H__ */
